package com.cty;

import com.cty.mapper.EmployeeMapper;
import com.cty.pojo.Employee;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;

public class test {

    @Test
    public void test_01() throws IOException {
        //获得mybatis配置的文件输入流
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        //获得SqlSessionFactory工厂缓存文件对象
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream);
        //获得SqlSession对象
        SqlSession sqlSession = build.openSession();
        //获得EmployeeMapper接口代理的对象
        EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class);
        Employee employee = mapper.queryById(1);
        System.out.println(employee);
        //提交事务
        sqlSession.commit();
        //关闭连接
        sqlSession.close();
    }
}
